// 防抖
function debounce(callback, time) {
    let timer = null;
    return function (...args) {
        clearTimeout(timer);
        timer = setTimeout(() => {
            callback.apply(this, args)
        }, time)
    }
}

// 截流
function throttle(callback, time) {
    let DateTime = 0;
    return function (...args) {
        let now = Date.now();
        if (now - DateTime > time) {
            callback.apply(this, args);
            DateTime = Date.now()  // 放在外面一直会执行
        }
    }
}

// 截流方式2
function throttle2(callback, time) {
    let timer = null;
    return function (...args) {
        if (!timer) {      // 需要判断当前是否存在，保证只有个定时器
            timer = setTimeout(() => {
                timer = null;
                callback.call(this, ...args)
            }, time)
        }
    }
}